<!--
 * @Descripttion: 
 * @version: 3.1.6
 * @Author: Dandelion
 * @Date: 2019-12-03 13:35:54
 * @LastEditors: Jian
 * @LastEditTime: 2019-12-04 10:29:23
 -->
<template>
  <div class="hello">
    <div class="h-controller">
      <a class="h-logo" @click="changeLangEvent()">{{$t('m.music')}}</a>
      <div class="h_tab">
        <ul>
          <li>
            <span>
              <a href="">{{$t('m.myMusic')}}</a>
            </span>
          </li>
          <li>
            <span>
              <a href="">{{$t('m.friend')}}</a>
            </span>
          </li>
          <li>
            <span>
              <a href="">{{$t('m.musician')}}</a>
            </span>
          </li>
          <li>
            <span>
              <a href="">{{$t('m.download')}}</a>
            </span>
          </li>
        </ul>
      </div>
    </div>
    <el-dialog
      title="提示"
      :visible.sync="chooseLangDialogVisible"
    >
      <el-form :model="langForm">
        {{currentLang}}
        <el-radio-group v-model="langForm.radio">
          <el-radio
            v-for="item in lang"
            :label="item.label"
            :key="item.label"
          >{{item.txt}}</el-radio>
        </el-radio-group>
        <br /><br />
        <el-form-item>
          <el-button
            type="primary"
            size="small"
            @click="onSubmit"
          >确认</el-button>
        </el-form-item>
      </el-form>
    </el-dialog>
  </div>
</template>

<script>
import { mapState } from "vuex";
export default {
  name: "HelloWorld",
  data() {
    return {
      /** 语言询问框显隐藏 */
      chooseLangDialogVisible: false,
      langForm: {
        radio: ""
      },
      lang: [
        {
          txt: "中文",
          label: "zh-CN"
        },
        {
          txt: "英文",
          label: "en-US"
        },
        {
          txt: "日文",
          label: "ja-JP"
        },
        {
          txt: "韩文",
          label: "re-KO"
        },
        {
          txt: "俄语",
          label: "ru-Ru"
        }
      ]
    };
  },
  methods: {
    changeLangEvent() {
      this.chooseLangDialogVisible = true;
    },
    onSubmit() {
      let self_current_lang = this.langForm.radio;
      if (self_current_lang) {
        // 切换系统语言
        this.$i18n.locale = self_current_lang;
        // 将新语言保存到全局状态管理
        this.$store.dispatch("update_current_lang", self_current_lang);
        // 关闭语言询问框
        this.chooseLangDialogVisible = false;
        // 成功提示
        this.$message.success("系统语言切换成功！");
      } else {
        this.$message.warning("没有你想要的语言吗，选一个吧！");
      }
    }
  },
  computed: {
    ...mapState({
      currentLang: function(state) {
        this.langForm.radio = state.currentLang;
      }
    })
  }
};
</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped>
h1,
h2 {
  font-weight: normal;
}
ul {
  list-style-type: none;
  padding: 0;
}
li {
  display: inline-block;
  margin: 0 10px;
}
a {
  color: #42b983;
}
</style>
